#!/usr/bin/env php
<?php

/*

Desktopd Picture Client
Copyright (C) 2015  Desktopd Developer(s)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

https://www.gnu.org/licenses/agpl.html

@kind entry-executable

*/


namespace Desktopd\PictureClient;

use Desktopd\PlatformTools;


/*
    Autoloader
*/
require_once dirname(__DIR__) . '/autoloader.php';


/*
    Load settings
*/
require_once dirname(__DIR__) . '/DefaultSettings.php';


PlatformTools\Log::setLogFile(__DIR__ . '/log_download-pictures.log');
PlatformTools\Log::setLogLevel(PlatformTools\Log::DEBUG);
PlatformTools\Log::setConsoleLogLevel(PlatformTools\Log::INFO);


/*
    Print what is this program
*/
PlatformTools\Log::log("Starting: $desktopdProductName, version $desktopdVersion", PlatformTools\Log::INFO);
PlatformTools\Log::log("Module: Picture Client", PlatformTools\Log::INFO);


PlatformTools\Log::log(
    "Requesting the list of available pictures: $pictureClientServerURI"
    , PlatformTools\Log::INFO
);
$client = new PictureClient($pictureClientServerURI);
$client->addLogger(new PlatformTools\CallbackLogger(function ($message, $level) {
    PlatformTools\Log::log($message, $level);
}));

$directory = $pictureClientPictureDirectory;
$client->downloadPictures($directory, $pictureClientTargetWidth, $pictureClientTargetHeight);

$client->deleteOldFiles($directory, $pictureClientMaxFiles);


// vim: ts=4 et ai

